var crypto = require('crypto'),
    User = require('../models/user.js'),
    Post = require('../models/post.js')
    fs = require('fs');

module.exports = function(app) {
  app.get('/', function (req, res) {
    Post.getAll(null, function (err, posts) {
      if (err) {
        posts = [];
      } 
      res.render('index', {
        title: 'Home',
        user: req.session.user,
        posts: posts,
        success: req.flash('success').toString(),
        error: req.flash('error').toString()
      });
    });
  });
  
  fs.readdirSync(__dirname).forEach(function(file) {
      if (file == "index.js") return;
      var name = file.substr(0, file.indexOf('.'));
      require('./' + name)(app);
  });
}